package com.engine.salary.enums.salaryitem;

import com.engine.salary.enums.BaseEnum;
import com.engine.salary.enums.SalaryValueTypeEnum;

import java.util.Arrays;
import java.util.Objects;

/**
 * 薪资项目的字段类型
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public enum SalaryDataTypeEnum implements BaseEnum<String> {
    STRING("string", "字符", 105093),
    NUMBER("number", "数值", 87625),
    ;

    private String value;

    private String defaultLabel;

    private int labelId;

    SalaryDataTypeEnum(String value, String defaultLabel, int labelId) {
        this.value = value;
        this.defaultLabel = defaultLabel;
        this.labelId = labelId;
    }

    @Override
    public String getValue() {
        return this.value;
    }

    @Override
    public Integer getLabelId() {
        return this.labelId;
    }

    @Override
    public String getDefaultLabel() {
        return this.defaultLabel;
    }

    public static SalaryDataTypeEnum parseByValue(String value) {
        for (SalaryDataTypeEnum salaryDataTypeEnum : SalaryDataTypeEnum.values()) {
            if (Objects.equals(salaryDataTypeEnum.getValue(), value)) {
                return salaryDataTypeEnum;
            }
        }
        return STRING;
    }

    public static String getDefaultLabelByValue(String value) {
        if (value == null) {
            return "";
        }
        SalaryDataTypeEnum[] enumAry = SalaryDataTypeEnum.values();
        for(int i = 0; i < Arrays.asList(enumAry).size(); i++){
            if (enumAry[i].getValue().equals(value)) {
                return enumAry[i].getDefaultLabel();
            }
        }
        return "";
    }

    public static SalaryDataTypeEnum parseByDefaultLabel(String defaultLabel) {
        for (SalaryDataTypeEnum typeEnum : SalaryDataTypeEnum.values()) {
            if (Objects.equals(typeEnum.getDefaultLabel(), defaultLabel)) {
                return typeEnum;
            }
        }
        return STRING;
    }
}
